#include "win/winimpl.h"
#include "base/common.h"

class CMainDlg
    : public WinImpl<CMainDlg>
    , public core::IMessageObserver
{
public:
    CMainDlg()
    {
    }

protected:
    BEGIN_CONTROL_MESSAGE_MAP()
        CONTROL_LBUTTONUP( "testbtn", OnClickTestBtn )
        CONTROL_LBUTTONUP( "close", OnClickClose )
    END_CONTROL_MESSAGE_MAP()

    BEGIN_MSG_MAP(CMainDlg)
        MESSAGE_HANDLER( WM_CREATE, OnCreate )
        MESSAGE_HANDLER( WM_DESTROY, OnDestroy )
        CHAIN_MSG_MAP(WinImpl<CMainDlg>)
    END_MSG_MAP()

    HRESULT OnCreate( UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL bHandled )
    {
        RegisterMessageObserver( "testbtn", this );
        RegisterMessageObserver( "close", this );

        common::WinHelper::CenterWindow( m_hWnd, NULL );
        return WinImpl<CMainDlg>::OnCreate( uMsg, wParam, lParam, bHandled );
    }

    HRESULT OnDestroy( UINT, WPARAM, LPARAM, BOOL )
    {
        ThreadManager::Instance().MessageQueue()->Quit();
        return TRUE;
    }

    void OnClickClose( const std::string id, core::uint wParam, core::uint lParam )
    {
        DestroyWindow();
    }

    void OnClickTestBtn( const std::string id, core::uint wParam, core::uint lParam )
    {
        /*Animate * animate = new Animate( "background" );
        (*animate).PutLinerAttribute( "alpha", 255, 0 );
        PutSingleAnimate( 30.0, 1000.0, animate );

        animate = new Animate( "background" );
        (*animate).PutLinerAttribute( "alpha", 0, 255 );
        PutSingleAnimate( 30.0, 1000.0, animate );

        animate = new Animate( "testbtn" );
        (*animate).PutLinerAttribute( "left", 100, 0 ).PutLinerAttribute( "alpha", 255, 0 );
        PutSingleAnimate( 30.0, 1000.0, animate );

        animate = new Animate( "testbtn" );
        (*animate).PutLinerAttribute( "left", 0, 100 ).PutLinerAttribute( "alpha", 0, 255 );
        PutSingleAnimate( 30.0, 1000.0, animate );*/

        /*Animate * animate1 = new Animate( "background" );
        (*animate1).PutLinerAttribute( "alpha", 255, 0 );

        Animate * animate2 = new Animate( "background" );
        (*animate2).PutLinerAttribute( "alpha", 0, 255 );

        Animate * animate3 = new Animate( "testbtn" );
        (*animate3).PutLinerAttribute( "alpha", 255, 0 );

        Animate * animate4 = new Animate( "testbtn" );
        (*animate4).PutLinerAttribute( "alpha", 0, 255 );

        ComplexAnimateHandler *pHandler = new ComplexAnimateHandler( 30.0, 1000.0 );
        pHandler->PutAnimate( animate1 );
        pHandler->PutAnimate( animate3 );

        PutComplexAnimate( pHandler );

        ComplexAnimateHandler *pHandler2 = new ComplexAnimateHandler( 30.0, 1000.0 );
        pHandler2->PutAnimate( animate2 );
        pHandler2->PutAnimate( animate4 );

        PutComplexAnimate( pHandler2 );*/

        Animate *animate = new Animate( "innerdiv" );
        (*animate).PutLinerAttribute( "width", 100, 40 ).PutLinerAttribute("height", 50, 10 );
        PutSingleAnimate( 30.0, 1000.0, animate );

        animate = new Animate( "innerdiv2" );
        (*animate).PutLinerAttribute( "width", 100, 40 ).PutLinerAttribute("height", 50, 10 );
        PutSingleAnimate( 30.0, 1000.0, animate );
    }
};